package java6681.regex;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Junichiro
 * @description 日期检测
 * @date 2021-03-15 0:56
 **/
/*
 * 分析：
 * 1.字符串切割逗号
 * 2.创建一个String数组用于存放切割后的字符
 * 3.切割后的字符放到字符串数组
 * 4.for遍历一个一个判断是否符合正则表达式
 * */
public class DateRegex {
    public static void main(String[] args) {
        String str = "2018-10,2018-05,2018-5,12-2018,2018-14,11,2018,-12";
        String regex = "\\d{4}-0?[1-9]|1[012]";
        String[] split = str.split(",");

        String[] arr = new String[split.length];

        for (int i = 0; i < arr.length; i++) {
            arr[i] = split[i];
            boolean matches = arr[i].matches(regex);
//            System.out.println(arr[i] + ":" + matches);
            if (i != arr.length-1){
                System.out.print(arr[i]+"、");
            }else {
                System.out.print(arr[i]);
            }

        }



    }
}
